
module Control(iOpcode,iFunction,oRegWrite,oRegDst,oALUSrc,oALUOp,oMemWrite,oMemtoReg,oPCSrc,oJump);

input [5:0]iOpcode;	// Opcode part which connected [31:26] Instruction
input [5:0]iFunction;	// Function part which connected [5:0] Instruction

output oRegWrite; 	// Write Enable of Register
output oRegDst;		// Selector of Mux which locate front of Register
output oALUSrc;		// Selector of Mux which locate front of ALU
output [2:0]oALUOp;	// Selector of ALU
output oMemWrite;	// Write Enable of Data Memory
output oMemtoReg;	// Selector of Mux which locate rear of Data Memory
output oPCSrc;		// Selector of Mux which locate on PC line
output oJump;		// Selector of Mux which locate on PC line


reg [9:0] Cont;		// Control Signal 

assign oRegWrite = Cont[9]; 	
assign oRegDst = Cont[8];		
assign oALUSrc = Cont[7];		
assign oALUOp[2:0] = Cont[6:4];	
assign oMemWrite = Cont[3];	
assign oMemtoReg = Cont[2];	
assign oPCSrc = Cont[1];	
assign oJump = Cont[0];

always @ (*)
begin
Cont <= 10'b0000000000;//default state
	if (iOpcode == 6'b000000)
	begin
		if (iFunction == 6'b100000)	 // add
			Cont <= 10'b1100100000;		
		else if (iFunction == 6'b100010) // sub
			Cont <= 10'b1101100000;		
		else if (iFunction == 6'b101010) // slt
			Cont <= 10'b1101110000;		
		else if (iFunction == 6'b100100) // and
			Cont <= 10'b1100000000;		
	end
	else if (iOpcode == 6'b001110) 		 // ori 
		Cont <= 10'b1010010000;
	else if (iOpcode == 6'b100011) 		 // lw
		Cont <= 10'b1010100100;
	else if (iOpcode == 6'b101011) 		 //sw
		Cont <= 10'b0010101000;
	else if (iOpcode == 6'b000100) 		 // beq
		Cont <= 10'b0001100010;
	else if (iOpcode == 6'b000010) 		 // j
		Cont <= 10'b0000000001;
end
endmodule
